--file: test.lua

DATA_DIR = Dir.global_config_path()
local dbconn = {
    json_file = DATA_DIR.."sqlite.json",
    db_file = DATA_DIR.."test.db"
}

if(fh_api_sqlite_delete_db(dbconn) == 0)
then
    print("sqlite delete test.db ok")
end

if(fh_api_sqlite_create_db(dbconn) == 0)
then
    print("sqlite create "..dbconn.db_file.." from "..dbconn.json_file.." ok")
end

print("**************************");

local insert_data = {
    times = 1510197596,
    src_ip = "1.2.3.4",
    src_port = 1234,
    dst_ip = "4.3.2.1",
    dst_port = 80,
    host = "www.sohu.com",
    url = "/api",
    data_src = "TCP",
    key = "username",
    value = "fenghuotest",
    rule_name = "xunishenfen"
};

if(fh_api_sqlite_insert(dbconn, "mingxi", insert_data) == 0)
then
    print("sqlite insert data to "..dbconn.db_file.." ok")
end

a=0
while( a < 5 )
do
    local insert_data = {
        times = 1510198596,
        src_ip = "192.168.2.2",
        src_port = 5002,
        dst_ip = "8.8.8.8",
        dst_port = 53,
        host = "dns1.google.com",
        data_src = "UDP",
        rule_name = "DNS"
    };
        
    if(fh_api_sqlite_insert(dbconn, "mingxi", insert_data) == 0)
    then
        print("sqlite insert data to "..dbconn.db_file.." ok")
    end

    a = a+1
end

--count：查询到的结果数量，0表示找不到
local count = fh_api_sqlite_query(dbconn, "mingxi", "src_port=5002");

if(fh_api_sqlite_delete_db(dbconn) == 0)
then
    print("sqlite delete test.db ok")
end

os.exit(0);